﻿using Dogshow.Model.Extensions;
using Dogshow.Model.Validation;
using FluentValidation.Attributes;

namespace Dogshow.Model
{
    [Validator(typeof(KinologValidator))]
    public class Kinolog : Entity
    {
        public int Id { get; set; }
        private string m_ImeIPrezime;
        public string ImeIPrezime
        {
            get { return m_ImeIPrezime; }
            set
            {
                if (ImeIPrezime != value)
                {
                    m_ImeIPrezime = value;
                    OnPropertyChanged("ImeIPrezime");
                }
            }
        }

        private string m_Telefon;
        public string Telefon
        {
            get { return m_Telefon; }
            set
            {
                if (Telefon != value)
                {
                    m_Telefon = value;
                    OnPropertyChanged("Telefon");
                }
            }
        }

        private string _adresa;
        public string Adresa
        {
            get { return _adresa; }
            set
            {
                if (Adresa != value)
                {
                    _adresa = value.TrimNullAndToSentence();
                    OnPropertyChanged("Adresa");
                }
            }
        }

        private int? _idMesta;
        public int? IdMesta
        {
            get { return _idMesta; }
            set
            {
                if (IdMesta != value)
                {
                    _idMesta = value;
                    OnPropertyChanged("IdMesta");
                }
            }
        }

        private Mesto _mesto;
        public Mesto Mesto
        {
            get { return _mesto; }
            set
            {
                if (Mesto != value)
                {
                    _mesto = value;
                    OnPropertyChanged("Mesto");
                }
            }
        }

        public VrstaKinologa VrstaKinologa { get; set; }

        public bool Equals(Kinolog other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.Id == Id;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Kinolog)) return false;
            return Equals((Kinolog) obj);
        }

        public override int GetHashCode()
        {
            return Id;
        }

        public override void FixForeignKeys()
        {
            if (Mesto != null)
            {
                IdMesta = Mesto.Id;
            }
        }
    }
}